package com.job.liushuang.HomeWork0715;

/**
 * @author Liushuang
 * @version 1.0
 * @since 2022-07-15 20:23:21
 */
public class StringCompare {
    public static void main(String[] args) {
        String name1="lucy",name2="luck";
        System.out.println(name1.compareTo(name2));
        System.out.println("luc".compareTo(name2));//小于的返回负数
        System.out.println("luck".compareTo(name2));//一样的返回0
        //compareTo方法本质上是String类型实现java.lang.Comparable接口的方法
        //一个类型的对象之间如果想要有可比性（顺序上）就得实现java.lang.Comparable接口并重写compareTo方法

        String s1=new String(new char[]{'A',1,'!'});
        s1=s1+name1;//连接
        System.out.println(s1);
        s1.concat("1999");//concat方法只能接受字符串类型的参数
        System.out.println(s1);

        String url="https://cn.bing.com/search?q=GDP%E5%A2%9E%E9%95%BF&cvid=e5c7316cc1f54120b39422fca2e44447&aqs=edge..69i57j0l8.3739j0j4&FORM=ANAB01&PC=DCTS" ;
        System.out.println(url.contains("homepage"));
        System.out.println(url.contains("netease"));

        String url2="http://www.baidu.com/news/imgs/boom.jpg";
        System.out.println(url2.endsWith(".png")||url2.endsWith(".jpg"));
        System.out.println(url2.startsWith("https")||url2.startsWith("http"));

        //返回某字符或子串在当前字符串里的第一次出现的下标
        //返回某字符或某字串在当前字符串里的指定下标以后第一次出现的下标
        //如果没出现过，则返回-1

        String url3="http://www.baidu.com/news/baiduNews/today/XXX.html";
        System.out.println(url3.indexOf("baidu"));//12
        System.out.println(url3.indexOf("baidu",12+"baidu".length()));//27
        System.out.println(url3.indexOf('!'));

        //练习：一串字符，计算hello这个单词出现了多少次 “ahellobhellochelloohellodhellohello”
        String ss="ahellobhellochelloohellodhellohello";
        int index=-1;//存放每次查找到的下标
        int findStarIndex=0;//找到开始下标
        int counts=0;//次数
        // String find="a";或者设置一个find，下面把hello换成find
        while ((index=ss.indexOf("hello",findStarIndex))!=-1){
            counts++;
            findStarIndex=index+"hello".length();
        }
        System.out.println(counts);
    }
}
